package cn.imnaer.service.rpc.userinfo.dao;

import cn.imnaer.database.BaseDao;
import cn.imnaer.database.MatchConst;
import cn.imnaer.database.define.DBConstant;
import cn.imnaer.service.persistence.model.UserPermission;
import cn.imnaer.service.persistence.model.consts.USER_PERMISSION;

import org.bson.BSONObject;
import org.bson.BasicBSONObject;

import java.util.List;

/**
 * Created by Administrator on 2015/5/22.
 */
public class UserPermissionDaoImpl extends BaseDao<UserPermission> {
    private static UserPermissionDaoImpl instance = new UserPermissionDaoImpl();
    private UserPermissionDaoImpl() {
    }
    public static UserPermissionDaoImpl getInstance() {
        return instance;
    }
    public UserPermission findByUserId(String userId)  {
        return  this.findOneByAttribute("userId", userId)
        		
     		

        		
        		;
    }
    public List<UserPermission> findByUserIds(List<String> userIds)  {
        BasicBSONObject query = new BasicBSONObject();
        BasicBSONObject match = new BasicBSONObject();
        match.put(MatchConst._IN, userIds);
        query.put(USER_PERMISSION.userId, match);
        List<UserPermission> records = this.findAll(query, null);
        return records;
    }

    public boolean createPermissionForUser(String userId) {
        UserPermission userPermission = new UserPermission();
        userPermission.setUserId(userId);
        this.instance.insert(userPermission,true);
        return true;
    }
	@Override
	protected String getDbSpaceName() {
		return DBConstant.SPACE.USER_INFO_SPACE;
	}
	@Override
	protected String getDbCollectionName() {
		return DBConstant.COLLECTION.USER_PERMISSION_INFO_COLLECTION;
	}

	@Override
	protected String getPrimaryKey() {
		return  super.primaryKey = USER_PERMISSION.permissionId;
	}


}
